" 禁止使用方向键
nnoremap <Left> :echo "使用 h 左移"<CR>
nnoremap <Right> :echo "使用 l 右移"<CR>
nnoremap <Up> :echo "使用 k 上移"<CR>
nnoremap <Down> :echo "使用 j 下移"<CR>


" 控制分屏窗口大小
map <silent> <F9> <Esc>:vertical resize +3<CR>
map <silent> <F10> <Esc>:vertical resize -3<CR>
map <silent> <F11> <Esc>:resize +3<CR>
map <silent> <F12> <Esc>:resize -3<CR>


" buffer间切换
nnoremap <silent> [- :bprevious<CR>
nnoremap <silent> [= :bnext<CR>

let mapleader = "," "定义<leader>键
set mouse=a
inoremap <leader>a <Esc>:set mouse=a <bar> set nu <bar> set relativenumber<cr>
nnoremap <leader>a :set mouse=a <bar> set nu <bar> set relativenumber<cr>
inoremap <leader>v <Esc>:set mouse=v <bar> set nonu <bar> set norelativenumber<cr>
nnoremap <leader>v :set mouse=v <bar> set nonu <bar> set norelativenumber<cr>
set backspace=indent,eol,start
let loaded_matchparen=1 "关闭括号自动高亮
nnoremap <space>v <c-v>
"设置';y'复制到windows剪切板
noremap ;y : !/mnt/c/Windows/System32/clip.exe<cr>u
"}}}

"Tab management
" Create a new tab with tu
map te :tabe<CR>
" Move around tabs with tn and ti
map tp :-tabnext<CR>
map tn :+tabnext<CR>
" Move the tabs with tmn and tmi
map tmn :-tabmove<CR>
map tmi :+tabmove<CR>
"Close the tab
map tc :+tabc<CR>   "close current tab
map to :+tabo<CR>   "close all other tab
map ts :+tabs<CR>   "close all open tab
" Go to tab by number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>

"{{{优化设置
"设置y从vim复制到剪切板
set clipboard+=unnamed 
"映射 esc 键为 jj
imap jj <Esc>
"快速打开vim配置文件：_vimrc
nnoremap <leader>e :e $HOME/.config/nvim/init.vim<cr>
"刷新配置
nnoremap <leader>r :source $MYVIMRC<cr>
" 插入模式、正常模式按 Ctrl+u 快速转换为大写
inoremap <c-u> <esc>viwUea
nnoremap <c-u> viwUe
" 插入模式、正常模式按 Ctrl+u+u 快速转换为小写
inoremap <c-u><c-u> <esc>viwuea
nnoremap <c-u><c-u> viwue

"Ctrl+d 复制本行并粘贴到一下行
nnoremap <c-d> yyp

" <leader>+q 快速退出vim
nmap <leader>q :q!<cr>
nmap <leader>w :w!<cr>
imap <leader>q <Esc>:q!<cr>
imap <leader>w <Esc>:w!<cr>

"insert move
inoremap <C-f> <Right>
inoremap <C-b> <Left>
inoremap <C-a> <C-o>^
inoremap <C-e> <C-o>$

"复制模式进入和退出
nnoremap <leader><leader>v :set paste<cr>
inoremap <leader><leader>v <Esc>:set paste<cr>
"插入模式快速到另一个字符右边，对于配对的符号（如括号）很有用
imap <c-a> <Esc>LA
"插入模式移动到下一行
imap <c-o> <Esc>o
"移动到末尾
imap <c-e> <Esc>A
"关闭record
map q <nop>
"若打开分割窗口，可快速切换窗口
"快捷键提示：Ctrl+w w 切换窗口; Ctrl+w s 水平分割; Ctrl+w v 竖直分割
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l

"buffer change
nnoremap <c-n> :bn<cr>
"nnoremap <c-p> :bp<cr>
nnoremap <leader>d :bd<cr>

"设置跳出自动补全的括号
func SkipBracker()
    if getline('.')[col('.') - 1] == ')' || getline('.')[col('.') - 1] == ']' || getline('.')[col('.') - 1] == '"' || getline('.')[col('.') - 1] == "'" || getline('.')[col('.') - 1] == '}'
        return "\<ESC>la"
    else
        return "\t"
    endif
endfunc
" 将tab键绑定为跳出括号
inoremap <leader><tab> <c-r>=SkipBracker()<CR>
